package com.mayy.spark.demo.dataset;

import lombok.Data;
import org.apache.spark.sql.Dataset;
import org.apache.spark.sql.Row;
import org.apache.spark.sql.SparkSession;

import java.io.Serializable;

public class JavaSparkSQLExample {
    @Data
    public static class Person implements Serializable{
        private String name;
        private long age;
    }

    public static void main(String[] args) {
        SparkSession sparkSession=SparkSession.builder()
                .appName("JavaSparkSQLExample")
                .config("spark.some.config.option", "some-value")
                .master("local[*]")
                .getOrCreate();
        runBasicDataFrameExample(sparkSession);

    }

    private static void runBasicDataFrameExample(SparkSession spark) {
        Dataset<Row> df = spark.read().json("spark-offical-demo/src/main/resources/people.json");
        df.show();
        df.printSchema();
        df.select("name").show();
    }
}
